﻿using System.Text;
using RpcHelper;
using RpcHelper.Config;

namespace HttpService.Config
{
    internal class HttpConfig : IHttpConfig
    {
        private static readonly DefHttpConfig _Config;
        static HttpConfig()
        {
            _Config = new DefHttpConfig
            {
                CertHashVal = LocalConfig.Local["http:certHashVal"],
                Log = LocalConfig.Local.GetValue("http:log", new LogConfig()),
                ResponseEncoding = LocalConfig.Local.GetValue("http:responseEncoding", "utf-8"),
                File = LocalConfig.Local.GetValue<HttpFileConfig>("http:file", new HttpFileConfig()),
                Gzip = LocalConfig.Local.GetValue<GzipConfig>("http:gzip", new GzipConfig()),
                Up = LocalConfig.Local.GetValue<UpConfig>("http:up", new UpConfig
                {
                    MemoryUpSize = 10485760
                })
            };
            _Config.init();
        }
        public HttpFileConfig File => _Config.File;

        public GzipConfig Gzip => _Config.Gzip;

        public UpConfig Up => _Config.Up;

        /// <summary>
        /// 证书的Hash值
        /// </summary>
        public string CertHashVal => _Config.CertHashVal;
        /// <summary>
        /// 日志配置
        /// </summary>
        public LogConfig Log => _Config.Log;

        /// <summary>
        /// 响应编码
        /// </summary>
        public Encoding ResponseEncoding => _Config.Encoding;

        public void AddFileConfig(HttpFileConfig config)
        {
            config.Init();
        }
    }
}
